home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / prgs / Misc / SubTask.b < prev   
Text File  |  1996-09-10  |  1KB  |  52 lines

  1. {*
  2. ** An example of creating a sub-task in ACE.
  3. ** Adapted from RKM: Libraries (1991), p 467-468.
  4. *}
  5.  
  6. DEFLNG a-z
  7.  
  8. CONST stack_size = 1000&
  9. CONST big_num = &H8000000
  10.  
  11. LIBRARY "exec.library"
  12.  
  13. '..library functions
  14. DECLARE FUNCTION _Wait(signal&) LIBRARY exec
  15. DECLARE FUNCTION Forbid() LIBRARY exec
  16. DECLARE FUNCTION Permit() LIBRARY exec
  17.  
  18. '..external functions (ami.lib)
  19. DECLARE FUNCTION CreateTask&(taskname$,pri&,initPC&,stackSize&) EXTERNAL
  20. DECLARE FUNCTION DeleteTask(task&) EXTERNAL
  21.  
  22. '..stack-allocated global variables
  23. ADDRESS task
  24.  
  25. '..static global variables
  26. GLOBAL LONGINT sharedvar
  27.  
  28. '..subprograms
  29. SUB simpletask
  30.   while sharedvar < big_num
  31.     ++sharedvar
  32.   wend
  33.   _Wait(0)
  34. END SUB
  35.  
  36. '..main
  37. sharedvar = 0
  38. Print "Initial value of shared variable:";sharedvar
  39.  
  40. task = CreateTask("SimpleTask",0&,@simpletask,stack_size)
  41.  
  42. If task <> 0& Then
  43.   Print "A sub-task has been spawned which is currently"
  44.   Print "incrementing a variable that is shared between"
  45.   Print "the main task and the sub-task."
  46.   Input "Press return...",x$
  47.   Print "The value of the shared variable is now:";sharedvar
  48.   Forbid
  49.   DeleteTask(task)
  50.   Permit
  51. End If
  52.